import { z } from 'zod';

export const loginSchema = z.object({
  identifier: z.string().min(1, 'Please enter email or phone number').trim(),
  password: z.string().min(8, 'Password must be at least 8 characters')
    .regex(/(?=.*[a-z])(?=.*[A-Z])(?=.*\d)/, 'Must contain uppercase, lowercase letters and numbers'),
});

export type LoginSchema = z.infer<typeof loginSchema>;

export const registerSchema = z.object({
  email: z.string().email('Invalid email format').optional().or(z.literal('')),
  phone: z.string().regex(/^$|^1[3-9]\d{9}$/, 'Invalid phone number format'),
  password: z.string().min(8, 'Password must be at least 8 characters')
    .regex(/(?=.*[a-z])(?=.*[A-Z])(?=.*\d)/, 'Must contain uppercase, lowercase letters and numbers'),
  gender: z.enum(['MALE', 'FEMALE', 'UNKNOWN']),
  nickname: z.string().max(50).optional().or(z.literal('')),
}).refine(v => !!v.email || !!v.phone, { message: 'At least one of email or phone number must be provided', path: ['email'] });

export type RegisterSchema = z.infer<typeof registerSchema>;